package com.demo2do.fms.admin.dao.vehicle;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.demo2do.fms.entity.supplier.common.Supplier;
import com.demo2do.fms.entity.vehicle.AuditStatus;
import com.demo2do.fms.entity.vehicle.DeclareStatus;
import com.demo2do.fms.entity.vehicle.trailer.Trailer;

/**
 *
 * @author Ark
 *
 */
@Dao("hibernate")
public interface TrailerDao {

    /**
     * @return
     */
    @Query("SELECT COUNT(*) FROM Trailer WHERE disabled = false")
    public int count();
    
    /**
     * @param supplier
     * @return
     */
    @Query("SELECT COUNT(*) FROM Trailer WHERE disabled = false AND supplier = :supplier")
    public int count(@Variable("supplier") Supplier supplier);
    
    /**
     * @param status
     * @return
     */
    @Query("SELECT COUNT(*) FROM Trailer WHERE disabled = false AND status = :status")
    public int count(@Variable("status") AuditStatus status);
    
    /**
     * @param status
     * @param declareStatus
     * @return
     */
    @Query("SELECT COUNT(*) FROM Trailer WHERE disabled = false AND status IN(:statuses) AND declareStatus = :declareStatus")
    public int count(@Variable("statuses") List<AuditStatus> statuses, @Variable("declareStatus") DeclareStatus declareStatus);
    
    /**
     * @param supplier
     * @param status
     * @return
     */
    @Query("SELECT COUNT(*) FROM Trailer WHERE disabled = false AND supplier = :supplier AND status = :status")
    public int count(@Variable("supplier") Supplier supplier, @Variable("status") AuditStatus status);
    
    /**
     * @param supplierIds
     * @return
     */
    @Query("SELECT COUNT(*) FROM Trailer WHERE disabled = false AND supplier.id IN(:supplierIds)")
    public int countBySupplierIds(@Variable("supplierIds") List<Long> supplierIds);
    
    /**
     * @param supplierIds
     * @param status
     * @return
     */
    @Query("SELECT COUNT(*) FROM Trailer WHERE disabled = false AND supplier.id IN(:supplierIds) AND status = :status")
    public int countBySupplierIds(@Variable("supplierIds") List<Long> supplierIds, @Variable("status") AuditStatus status);
    
    /**
     * @param supplierIds
     * @param status
     * @param declareStatus
     * @return
     */
    @Query("SELECT COUNT(*) FROM Trailer WHERE disabled = false AND supplier.id IN(:supplierIds) AND status IN(:statuses) AND declareStatus = :declareStatus")
    public int countBySupplierIds(@Variable("supplierIds") List<Long> supplierIds, @Variable("statuses") List<AuditStatus> statuses, @Variable("declareStatus") DeclareStatus declareStatus);
    
    /**
     * @param brandCNCode
     * @return
     */
    @Query("SELECT COUNT(*) FROM Trailer WHERE disabled = false AND brandCNCode = :brandCNCode")
    public int countByBrandCNCode(@Variable("brandCNCode") String brandCNCode);
    
    /**
     * @param benginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Trailer WHERE disabled = false")
    public List<Trailer> list(@Variable("beginIndex")int benginIndex, @Variable("maxResult")int maxResult);
    
    /**
     * @param ids
     * @return
     */
    @Query("FROM Trailer WHERE disabled = false AND id IN(:ids)")
    public List<Trailer> list(@Variable("ids") List<Long> ids);
    
    /**
     * @param status
     * @return
     */
    @Limit
    @Query("FROM Trailer WHERE disabled = false AND status = :status ORDER BY lastModifyTime DESC")
    public List<Trailer> list(@Variable("status") AuditStatus status, @Variable("beginIndex")int benginIndex, @Variable("maxResult")int maxResult);
    
    /**
     * @param status
     * @param declareStatus
     * @param benginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Trailer WHERE disabled = false AND status IN(:statuses) AND declareStatus = :declareStatus")
    public List<Trailer> list(@Variable("statuses") List<AuditStatus> statuses, @Variable("declareStatus") DeclareStatus declareStatus, @Variable("beginIndex")int benginIndex, @Variable("maxResult")int maxResult);
    
    /**
     * @param supplier
     * @return
     */
    @Query("FROM Trailer WHERE disabled = false AND supplier = :supplier")
    public List<Trailer> list(@Variable("supplier") Supplier supplier);
    
    /**
     * @param supplier
     * @param benginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Trailer WHERE disabled = false AND supplier = :supplier")
    public List<Trailer> list(@Variable("supplier") Supplier supplier, @Variable("beginIndex")int benginIndex, @Variable("maxResult")int maxResult);
    
    /**
     * @param supplier
     * @param status
     * @param benginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Trailer WHERE disabled = false AND supplier = :supplier AND status = :status ORDER BY lastModifyTime DESC")
    public List<Trailer> list(@Variable("supplier") Supplier supplier, @Variable("status") AuditStatus status, @Variable("beginIndex")int benginIndex, @Variable("maxResult")int maxResult);
    
    /**
     * @param supplier
     * @param status
     * @return
     */
    @Query("FROM Trailer WHERE disabled = false AND supplier = :supplier AND status = :status")
    public List<Trailer> list(@Variable("supplier") Supplier supplier, @Variable("status") AuditStatus status);
    
    /**
     * @param supplier
     * @param status
     * @param bind
     * @return
     */
    @Query("FROM Trailer WHERE disabled = false AND supplier = :supplier AND status = :status AND bind = :bind")
    public List<Trailer> list(@Variable("supplier") Supplier supplier, @Variable("status") AuditStatus status, @Variable("bind") boolean bind);
    
    /**
     * @param supplierIds
     * @param benginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Trailer WHERE disabled = false AND supplier.id IN(:supplierIds)")
    public List<Trailer> listBySupplierIds(@Variable("supplierIds") List<Long> supplierIds, @Variable("beginIndex")int benginIndex, @Variable("maxResult")int maxResult);
    
    /**
     * @param supplierIds
     * @param status
     * @param declareStatus
     * @param benginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Trailer WHERE disabled = false AND supplier.id IN(:supplierIds) AND status IN(:statuses) AND declareStatus = :declareStatus")
    public List<Trailer> listBySupplierIds(@Variable("supplierIds") List<Long> supplierIds, @Variable("statuses") List<AuditStatus> statuses, @Variable("declareStatus") DeclareStatus declareStatus, @Variable("beginIndex")int benginIndex, @Variable("maxResult")int maxResult);
    
    /**
     * @param brandCNCode
     * @return
     */
    @Query("FROM Trailer WHERE disabled = false AND brandCNCode = :brandCNCode")
    public Trailer getByBrandCNCode(@Variable("brandCNCode") String brandCNCode);
    
}
